using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FitnessClub.Bll.StaffManager;
using System.Collections.Generic;

public partial class Employees : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = Delegate.getAllEmployee();
            GridView1.DataBind();
        }

    }


    protected void AddEmployee_Click(object sender, EventArgs e)
    {
        Response.Redirect("EmployeesAdd.aspx");


    }

    protected void ZwolnijEmployee_Click(object sender, EventArgs e)
    {
        Button but = (Button)sender;
        int id = int.Parse(but.CommandName);

        ResSEmp result = Delegate.sackEmployee(id);
        if (!result.IsOk)
        {
            lblErrorSackEmployee.Visible = true;
        }
        else
            Response.Redirect("Employees.aspx");
        //StateManager.Instance.AddToSession(SessionKeys.EmployeeId, id);

        //int l = StateManager.Instance.GetFromSession<int>(SessionKeys.EmployeeId);

    }

    protected void PrzypiszEmployee_Click(object sender, EventArgs e)
    {
        Button but = (Button)sender;
        int id = int.Parse(but.CommandName);
        StateManager.Instance.AddToSession(SessionKeys.EmployeeId, id);
        Response.Redirect("EmployeesServices.aspx");
    }

    protected void HolidaysEmployee_Click(object sender, EventArgs e)
    {
        Button but = (Button)sender;
        int id = int.Parse(but.CommandName);
        StateManager.Instance.AddToSession(SessionKeys.EmployeeId, id);
        Response.Redirect("EmployeesHolidays.aspx");

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
        {
            return;
        }

        ResListEmp res = (ResListEmp)e.Row.DataItem;

        ((Label)e.Row.FindControl("lblNazwisko")).Text = res.Surname;
        ((Label)e.Row.FindControl("lblImie")).Text = res.Name;

        ((Button)e.Row.FindControl("btnZwolnij")).CommandName = res.Id.ToString();
        ((Button)e.Row.FindControl("btnPrzypisz")).CommandName = res.Id.ToString();
        ((Button)e.Row.FindControl("btnNieobecnosci")).CommandName = res.Id.ToString();
      
    }
}
